﻿using BPMN.Application.Contracts.DTO.Request.Plan;
using BPMN.Application.IService;
using BPMN.Domain.Entity.Scheduling;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BPMN.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PlanController : ControllerBase
    {
        public PlanController(IPlanAppService plan)
        {
            Plan = plan;
        }

        public IPlanAppService Plan { get; }

        /// <summary>
        /// 排班计划
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetPlan(string plan_name, int pageIndex, int pageSize )
        {
            int totalCount;  int pagerCount;
            object list = Plan.GetPlan(plan_name, pageIndex, pageSize, out totalCount, out pagerCount);
            return Ok(new {list,totalCount,pagerCount});
        }
        /// <summary>
        /// 添加排班计划
        /// </summary>
        /// <param name="plan"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddPlan(Plan plan)
        {
            return Ok(Plan.AddPlan(plan));
        }
        /// <summary>
        /// 删除排班计划
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult DeletePlan(int id)
        {
            return Ok(Plan.DeletePlan(id));
        }


        /// <summary>
        /// 修改排班计划
        /// </summary>
        /// <param name="plan"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult UpdatePlan(Plan plan)
        {
            return Ok(Plan.UpdatePlan(plan));
        }
        /// <summary>
        /// 列表类型显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetPlan_Type()
        {
            return Ok(Plan.GetPlan_Type());
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult plDelete(string ids)
        {
            List<long> id = ids.Split(',').Select(x => Convert.ToInt64(x)).ToList();
            return Ok(Plan.plDelete(id));
        }
        /// <summary>
        /// 通过id获取排班计划
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetPlanById(int id)
        {
            return Ok(Plan.GetPlanById(id));
        }
    }
}
